package com.cmccgz.baselibrary.view;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.ScrollView;

import com.cmccgz.baselibrary.interfaces.OnObservableScrollListener;


/**
 * 由于scrollview的滑动监听需要23以上才可以监听，
 * 这个类给滑动事件暴露出去
 * @author INX
 */
public class ObservableScrollView extends ScrollView {

    private OnObservableScrollListener scrollViewListener = null;

    public ObservableScrollView(Context context) {
        super(context);
    }

    public ObservableScrollView(Context context, AttributeSet attrs,
                                int defStyle) {
        super(context, attrs, defStyle);
    }

    public ObservableScrollView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public void setScrollViewListener(OnObservableScrollListener scrollViewListener) {
        this.scrollViewListener = scrollViewListener;
    }

    @Override
    protected void onScrollChanged(int x, int y, int oldx, int oldy) {
        super.onScrollChanged(x, y, oldx, oldy);
        if (scrollViewListener != null) {
            scrollViewListener.onScrollChanged(this, x, y, oldx, oldy);
        }
    }

}
